# eric7.Project.ProjectTranslationsBrowser

Module implementing a class used to display the translations part of the project.

### Global Attributes

None

### Classes

ProjectTranslationsBrowser | A class used to display the translations part of the project.

### Functions

_elementTreeXmlString | Function to generate an XML string from a given element using our specialized escape function.
_escape_cdata_linguist | Function to escape character data iaw.

## ProjectTranslationsBrowser

A class used to display the translations part of the project.

### Signals

appendStderr(str)
  emitted after something was received from a QProcess on stderr
appendStdout(str)
  emitted after something was received from a QProcess on stdout
showMenu(str, QMenu)
  emitted when a menu is about to be shown. The name of the menu and a reference to the menu are given.

### Derived from

ProjectBaseBrowser

### Class Attributes

None

### Class Methods

None

### Methods

ProjectTranslationsBrowser | Constructor
__TRPreview | Private slot to handle the Preview translations action.
__TRPreviewAll | Private slot to handle the Preview all translations action.
__addTranslationFiles | Private method to add translation files to the project.
__deleteLanguageFile | Private method to delete a translation file from the project.
__extractMessages | Private slot to extract the messages to form a messages template file.
__generateAll | Private method to generate all translation files (.ts) for Qt Linguist.
__generateObsoleteAll | Private method to generate all translation files (.ts) for Qt Linguist.
__generateObsoleteSelected | Private method to generate selected translation files (.ts) for Qt Linguist.
__generateSelected | Private method to generate selected translation files (.ts) for Qt Linguist.
__generateTSFile | Private method used to run pylupdate5 / pylupdate6 / pyside6-lupdate to generate the .ts files.
__generateTSFileDone | Private slot to handle the finished signal of the pylupdate process.
__openFileInEditor | Private slot to handle the Open in Editor menu action.
__postProcessTSFile | Private method to post process the generated .ts file.
__readStderr | Private method to read from a process' stderr channel.
__readStderrLrelease | Private slot to handle the readyReadStandardError signal of the lrelease process.
__readStderrLupdate | Private slot to handle the readyReadStandardError signal of the pylupdate5 / pylupdate6 / pyside6-lupdate process.
__readStdout | Private method to read from a process' stdout channel.
__readStdoutLrelease | Private slot to handle the readyReadStandardOutput signal of the lrelease process.
__readStdoutLupdate | Private slot to handle the readyReadStandardOutput signal of the pylupdate process.
__releaseAll | Private method to release the translation files (.qm).
__releaseSelected | Private method to release the translation files (.qm).
__releaseTSFile | Private method to run lrelease to release the translation files (.qm).
__releaseTSFileDone | Private slot to handle the finished signal of the lrelease process.
__removeLanguageFile | Private method to remove a translation from the project.
__showContextMenu | Private slot called by the menu aboutToShow signal.
__showContextMenuBack | Private slot called by the backMenu aboutToShow signal.
__showContextMenuDir | Private slot called by the dirMenu aboutToShow signal.
__showContextMenuMulti | Private slot called by the multiMenu aboutToShow signal.
__writeTempProjectFile | Private method to write a temporary project file suitable for pylupdate and lrelease.
_contextMenuRequested | Protected slot to show the context menu.
_createPopupMenus | Protected overloaded method to generate the popup menu.
_initHookMethods | Protected method to initialize the hooks dictionary.
_openItem | Protected slot to handle the open popup menu entry.
getIcon | Public method to get an icon for the project browser.

### Static Methods

None

#### ProjectTranslationsBrowser (Constructor)

ProjectTranslationsBrowser(project, projectBrowser, parent=None)

Constructor

project (Project)
  reference to the project object
projectBrowser (ProjectBrowser)
  reference to the project browser object
parent (QWidget)
  parent widget of this browser

#### ProjectTranslationsBrowser.__TRPreview

__TRPreview(previewAll=False)

Private slot to handle the Preview translations action.

previewAll (bool)
  flag indicating, that all translations should be previewed

#### ProjectTranslationsBrowser.__TRPreviewAll

__TRPreviewAll()

Private slot to handle the Preview all translations action.

#### ProjectTranslationsBrowser.__addTranslationFiles

__addTranslationFiles()

Private method to add translation files to the project.

#### ProjectTranslationsBrowser.__deleteLanguageFile

__deleteLanguageFile()

Private method to delete a translation file from the project.

#### ProjectTranslationsBrowser.__extractMessages

__extractMessages()

Private slot to extract the messages to form a messages template file.

#### ProjectTranslationsBrowser.__generateAll

__generateAll()

Private method to generate all translation files (.ts) for Qt Linguist.

All obsolete strings are removed from the .ts file.

#### ProjectTranslationsBrowser.__generateObsoleteAll

__generateObsoleteAll()

Private method to generate all translation files (.ts) for Qt Linguist.

Obsolete strings are kept.

#### ProjectTranslationsBrowser.__generateObsoleteSelected

__generateObsoleteSelected()

Private method to generate selected translation files (.ts) for Qt Linguist.

Obsolete strings are kept.

#### ProjectTranslationsBrowser.__generateSelected

__generateSelected()

Private method to generate selected translation files (.ts) for Qt Linguist.

All obsolete strings are removed from the .ts file.

#### ProjectTranslationsBrowser.__generateTSFile

__generateTSFile(noobsolete=False, generateAll=True)

Private method used to run pylupdate5 / pylupdate6 / pyside6-lupdate to generate the .ts files.

noobsolete (bool)
  flag indicating whether obsolete entries should be kept
generateAll (bool)
  flag indicating whether all translations should be generated

#### ProjectTranslationsBrowser.__generateTSFileDone

__generateTSFileDone(proc, exitCode, exitStatus)

Private slot to handle the finished signal of the pylupdate process.

proc (QProcess)
  reference to the process
exitCode (int)
  exit code of the process
exitStatus (QProcess.ExitStatus)
  exit status of the process

#### ProjectTranslationsBrowser.__openFileInEditor

__openFileInEditor()

Private slot to handle the Open in Editor menu action.

#### ProjectTranslationsBrowser.__postProcessTSFile

__postProcessTSFile(tsFile)

Private method to post process the generated .ts file.

tsFile (str)
  project relative path of the .ts file

#### ProjectTranslationsBrowser.__readStderr

__readStderr(proc, ps)

Private method to read from a process' stderr channel.

proc (QProcess)
  process to read from
ps (str)
  propmt string

#### ProjectTranslationsBrowser.__readStderrLrelease

__readStderrLrelease(proc)

Private slot to handle the readyReadStandardError signal of the lrelease process.

proc (QProcess)
  reference to the process

#### ProjectTranslationsBrowser.__readStderrLupdate

__readStderrLupdate(proc)

Private slot to handle the readyReadStandardError signal of the pylupdate5 / pylupdate6 / pyside6-lupdate process.

proc (QProcess)
  reference to the process

#### ProjectTranslationsBrowser.__readStdout

__readStdout(proc, ps)

Private method to read from a process' stdout channel.

proc (QProcess)
  process to read from
ps (str)
  prompt string

Return:
  string read from the process

Return Type:
  str

#### ProjectTranslationsBrowser.__readStdoutLrelease

__readStdoutLrelease(proc)

Private slot to handle the readyReadStandardOutput signal of the lrelease process.

proc (QProcess)
  reference to the process

#### ProjectTranslationsBrowser.__readStdoutLupdate

__readStdoutLupdate(proc)

Private slot to handle the readyReadStandardOutput signal of the pylupdate process.

proc (QProcess)
  reference to the process

#### ProjectTranslationsBrowser.__releaseAll

__releaseAll()

Private method to release the translation files (.qm).

#### ProjectTranslationsBrowser.__releaseSelected

__releaseSelected()

Private method to release the translation files (.qm).

#### ProjectTranslationsBrowser.__releaseTSFile

__releaseTSFile(generateAll=False)

Private method to run lrelease to release the translation files (.qm).

generateAll (bool)
  flag indicating whether all translations should be released

#### ProjectTranslationsBrowser.__releaseTSFileDone

__releaseTSFileDone(proc, exitCode, exitStatus)

Private slot to handle the finished signal of the lrelease process.

proc (QProcess)
  reference to the process
exitCode (int)
  exit code of the process
exitStatus (QProcess.ExitStatus)
  exit status of the process

#### ProjectTranslationsBrowser.__removeLanguageFile

__removeLanguageFile()

Private method to remove a translation from the project.

#### ProjectTranslationsBrowser.__showContextMenu

__showContextMenu()

Private slot called by the menu aboutToShow signal.

#### ProjectTranslationsBrowser.__showContextMenuBack

__showContextMenuBack()

Private slot called by the backMenu aboutToShow signal.

#### ProjectTranslationsBrowser.__showContextMenuDir

__showContextMenuDir()

Private slot called by the dirMenu aboutToShow signal.

#### ProjectTranslationsBrowser.__showContextMenuMulti

__showContextMenuMulti()

Private slot called by the multiMenu aboutToShow signal.

#### ProjectTranslationsBrowser.__writeTempProjectFile

__writeTempProjectFile(langs, filterList)

Private method to write a temporary project file suitable for pylupdate and lrelease.

langs (list of ProjectBrowserFileItem)
  list of languages to include in the process. An empty list (default) means that all translations should be included.
filterList (list of str)
  list of source file extension that should be considered

Return:
  flag indicating success

Return Type:
  bool

#### ProjectTranslationsBrowser._contextMenuRequested

_contextMenuRequested(coord)

Protected slot to show the context menu.

coord (QPoint)
  the position of the mouse pointer

#### ProjectTranslationsBrowser._createPopupMenus

_createPopupMenus()

Protected overloaded method to generate the popup menu.

#### ProjectTranslationsBrowser._initHookMethods

_initHookMethods()

Protected method to initialize the hooks dictionary.

Supported hook methods are:

- extractMessages: takes no parameters
- generateAll: takes list of filenames as parameter
- generateAllWithObsolete: takes list of filenames as parameter
- generateSelected: takes list of filenames as parameter
- generateSelectedWithObsolete: takes list of filenames as parameter
- releaseAll: takes list of filenames as parameter
- releaseSelected: takes list of filenames as parameter
- open: takes a filename as parameter

Note: Filenames are relative to the project directory.

#### ProjectTranslationsBrowser._openItem

_openItem()

Protected slot to handle the open popup menu entry.

#### ProjectTranslationsBrowser.getIcon

getIcon()

Public method to get an icon for the project browser.

Return:
  icon for the browser

Return Type:
  QIcon

Up

## _elementTreeXmlString

_elementTreeXmlString(xmlElement)

Function to generate an XML string from a given element using our specialized escape function.

Therefore the ElementTree._escape_cdata() function is replaced by the specialized one before output for the .ts file is created and changed back to the original afterwards.

xmlElement (xml.etree.ElementTree.Element)
  reference to the ElementTree Element object to be converted to a string

Return:
  string output of the element

Return Type:
  str

Up

## _escape_cdata_linguist

_escape_cdata_linguist(text)

Function to escape character data iaw. the way Qt Linguist does it.

The difference to the one used by ElementTree is that the ' and " characters are escaped as well.

text (str)
  text to be escaped

Return:
  escaped text

Return Type:
  str

Up